<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Stack {
            constructor() {
                    this.item = [];
                }
                //push()
            push(element) {
                    this.item.push(element);
                }
                //pop()
            pop() {
                    return this.item.pop();
                }
                //peek()
            peek() {
                    return this.item[this.size() - 1];
                }
                //size()
            size() {
                return this.item.length;
            }
            isEmpty() {
                return this.size() === 0;
            }
            toString() {
                return this.item.toString();
            }
        }

        function baseConverter(decNumber, base) {
            const remStack = new Stack();
            const digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            let number = decNumber;
            let rem;
            let baseString = '';
            if (!(base >= 2 && base <= 36)) {
                return '';
            }
            while (number > 0) {
                rem = Math.floor(number % base);
                remStack.push(rem);
                number = Math.floor(number / base)
            }
            while (!remStack.isEmpty()) {
                baseString += digits[remStack.pop()];
            }
            return baseString;

        }
        console.log(baseConverter(100345, 2));
    </script>
</body>

</html>